#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define LEN 81
#define SIMPLE
typedef void(*myCharFp)(char*);
char * s_gets(char *st, int n);
int showmenu(void);
void eatline(void);
void show(myCharFp fp, char *str);
void toUpperf(char *);
void toLowerf(char *);
void transpose(char *);
void dummy(char *);
myCharFp argFp[4]={toUpperf,toLowerf,transpose,dummy};
int main(){
	char line[LEN];
	char copy[LEN];
	int index;
	myCharFp pfun;
	puts("Enter a string (empty line to quit):");

	while(s_gets(line, LEN)!= NULL && line[0] != '\0'){
#ifdef SIMPLE
			index = showmenu();
			while(index>=0 && index <=3){
				strcpy(copy,line);
				show(argFp[index], copy);
				index = showmenu();
			}
#endif
#ifndef SIMPLE
			switch(choice){
				case 'u':pfun = toUpperf;break;
				case 'l':pfun = toLowerf;break;
				case 't':pfun = transpose;break;
				case 'o':pfun = dummy; break;
			}

			strcpy(copy, line);
			show(pfun, copy);
#endif
		
		puts("Enter a string(empty line to quit):");

	}
	puts("Bye!");
	return 0;
}
int showmenu(void){
	char ans;
	puts("Enter menu choice:");
	puts("u)up;l)low;t)transpose;o)origin;n)next string\n");
	ans = getchar();
	ans = tolower(ans);
	eatline();
	while(strchr("ulton", ans) == NULL){
		puts("Please enter a u l t o or n:\n");
		ans = tolower(getchar());
		eatline();
	}
	return ans=='u'?0:ans=='l'?1:ans=='t'?2:ans=='o'?3:4;
}
void eatline(void){
	while(getchar() != '\n')continue;
}
void toUpperf(char *str){
	while(*str){
		*str = toupper(*str);
		str++;
	}
}
void toLowerf(char *str){
	while(*str){
		*str = tolower(*str);
		str++;
	}
}
void transpose(char *str){
	while(*str){
		if(islower(*str))
			*str = toupper(*str);
		else if(isupper(*str))
			*str = tolower(*str);
		str++;
	}	
}
void dummy(char *str){
	
}
void show(void(*fp)(char *), char *str){
	(*fp)(str);
	puts(str);
}
char *s_gets(char *st, int n){
	char *retVal;
	char *find;
	retVal = fgets(st, n, stdin);
	if(retVal){
		find = strchr(st, '\n');
		if(find) *find = '\0';
		else
			while(getchar() != '\n')continue;
	}
	return retVal;
}
